Imports System
Imports System.Collections
Imports System.Text
Imports System.XML
Imports DotNetNuke.Common.Utilities

Namespace DotNetNuke.Modules.ProjectTracker

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    '''		The ProjectsController class provides business layer methods
    '''		for Projects objects used by the ProjectTracker module.
    ''' </summary>
    ''' <remarks></remarks>
    ''' <history>
    '''		[MyGeneration]	3/19/2006 9:35:55 PM	Code file automatically generated from DotNetNuke.PT_Projects by MyGeneration v1.1.5.1
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Class ProjectsController

        Implements Entities.Modules.IPortable


        Public Sub New()
            ' default object initialisation	
        End Sub

#Region " Public Methods "

        ''' <summary>
        ''' Adds a new Projects record
        ''' </summary>
        ''' <returns>Identifier for the newly created object</returns>
        Public Function AddProjects(ByVal projectsInfo As ProjectsInfo) As Integer
            Return CType(DataProvider.Instance().AddProjects(projectsInfo.ModuleID, projectsInfo.CreatedByUser, projectsInfo.CreatedDate, projectsInfo.ProjectName, projectsInfo.Version, projectsInfo.ProjectLead, projectsInfo.ProjectChair, projectsInfo.Description, projectsInfo.Url, projectsInfo.CurrentState,projectsinfo.Status ), Integer)
        End Function


        ''' <summary>
        ''' Updates a specified Projects
        ''' </summary>
        ''' <returns></returns>
        Public Shared Sub UpdateProjects(ByVal projectsInfo As ProjectsInfo)
            DataProvider.Instance().UpdateProjects(projectsInfo.ItemID, projectsInfo.ModuleID, projectsInfo.CreatedByUser, projectsInfo.CreatedDate, projectsInfo.ProjectName, projectsInfo.Version, projectsInfo.ProjectLead, projectsInfo.ProjectChair, projectsInfo.Description, projectsInfo.Url, projectsInfo.CurrentState, projectsInfo.Status)
        End Sub


        ''' <summary>
        ''' Deletes a specified Projects
        ''' </summary>
        ''' <returns></returns>
        Public Shared Sub DeleteProjects(ByVal itemID As Integer)
            DataProvider.Instance().DeleteProjects(itemID)
        End Sub


        ''' <summary>
        ''' Retrieves the details of a specified Projects
        ''' </summary>
        ''' <returns>ProjectsInfo object</returns>
        Public Function GetProjectsInfo(ByVal itemID As Integer) As ProjectsInfo
            Return CType(CBO.FillObject(DataProvider.Instance().GetProjectsInfo(itemID), GetType(ProjectsInfo)), ProjectsInfo)
        End Function


        ''' <summary>
        ''' Retrieves the entire list of ProjectsList
        ''' </summary>
        ''' <returns>ArrayList of ProjectsInfo objects</returns>
        Public Function GetProjectsList(ByVal moduleID As Integer, ByVal filter As String) As ArrayList
            Return CBO.FillCollection(DataProvider.Instance().GetProjectsList(moduleID, filter), GetType(ProjectsInfo))
        End Function


#End Region

#Region "Optional Interfaces"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' ExportModule implements the IPortable ExportModule Interface
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <param name="ModuleID">The Id of the module to be exported</param>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Function ExportModule(ByVal ModuleID As Integer) As String Implements Entities.Modules.IPortable.ExportModule
            Dim strXML As New StringBuilder

            Dim arrList As ArrayList = Me.GetProjectsList(ModuleID, "All")
            If arrList.Count <> 0 Then
                strXML.Append("<projectslist>")
                For Each objItem As ProjectsInfo In arrList
                    strXML.Append("<projects>")
                    strXML.Append("<itemid>XMLEncode(objItem.ItemID.ToString())</itemid>")
                    strXML.Append("<moduleid>XMLEncode(objItem.ModuleID.ToString())</moduleid>")
                    strXML.Append("<createdbyuser>XMLEncode(objItem.CreatedByUser.ToString())</createdbyuser>")
                    strXML.Append("<createddate>XMLEncode(objItem.CreatedDate.ToString())</createddate>")
                    strXML.Append("<projectname>XMLEncode(objItem.ProjectName.ToString())</projectname>")
                    strXML.Append("<version>XMLEncode(objItem.Version.ToString())</version>")
                    strXML.Append("<projectlead>XMLEncode(objItem.ProjectLead.ToString())</projectlead>")
                    strXML.Append("<projectchair>XMLEncode(objItem.ProjectChair.ToString())</projectchair>")
                    strXML.Append("<description>XMLEncode(objItem.Description.ToString())</description>")
                    strXML.Append("<url>XMLEncode(objItem.Url.ToString())</url>")
                    strXML.Append("<currentstate>XMLEncode(objItem.CurrentState.ToString())</currentstate>")
                    strXML.Append("</projects>")
                Next
                strXML.Append("</projectslist>")
            End If

            Return strXML.ToString()

        End Function

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' ImportModule implements the IPortable ImportModule Interface
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <param name="ModuleID">The Id of the module to be imported</param>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Sub ImportModule(ByVal ModuleID As Integer, ByVal Content As String, ByVal Version As String, ByVal UserId As Integer) Implements Entities.Modules.IPortable.ImportModule
            Dim xmlList As XmlNode = GetContent(Content, "projectslist")
            For Each xmlItem As XmlNode In xmlList.SelectNodes("projects")
                Dim objItem As New ProjectsInfo
                objItem.ItemID = CType(Null.GetNull(xmlItem.Item("itemid").InnerText, Null.NullInteger), Integer)
                objItem.ModuleID = CType(Null.GetNull(xmlItem.Item("moduleid").InnerText, Null.NullInteger), Integer)
                objItem.CreatedByUser = CType(Null.GetNull(xmlItem.Item("createdbyuser").InnerText, Null.NullInteger), Integer)
                objItem.CreatedDate = CType(Null.GetNull(xmlItem.Item("createddate").InnerText, Null.NullDate), DateTime)
                objItem.ProjectName = CType(Null.GetNull(xmlItem.Item("projectname").InnerText, Null.NullString), String)
                objItem.Version = CType(Null.GetNull(xmlItem.Item("version").InnerText, Null.NullString), String)
                objItem.ProjectLead = CType(Null.GetNull(xmlItem.Item("projectlead").InnerText, Null.NullInteger), Integer)
                objItem.ProjectChair = CType(Null.GetNull(xmlItem.Item("projectchair").InnerText, Null.NullInteger), Integer)
                objItem.Description = CType(Null.GetNull(xmlItem.Item("description").InnerText, Null.NullString), String)
                objItem.Url = CType(Null.GetNull(xmlItem.Item("url").InnerText, Null.NullString), String)
                objItem.CurrentState = CType(Null.GetNull(xmlItem.Item("currentstate").InnerText, Null.NullInteger), Integer)

                If objItem.ItemID = Null.NullInteger Then
                    Me.AddProjects(objItem)
                Else
                    Me.UpdateProjects(objItem)
                End If
            Next
        End Sub

#End Region


    End Class

End Namespace
